/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
package org.opentoast.maven;

import java.io.File;

import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;

/**
 * Generate an OSGi manifest for this project
 * 
 * TODO Use SpringSource Bundlor to generate MANEFEST.MF file
 * 
 * @author <a href="mailto:jiwhiz@gmail.com">Yuan Ji</a>
 * 
 * @goal manifest
 * @phase process-classes
 * @requiresDependencyResolution runtime
 */
public class ManifestMojo extends AbstractS2DMMojo
{
    /**
     * @see org.apache.maven.plugin.Mojo#execute()
     */
    public void execute()
        throws MojoExecutionException, MojoFailureException
    {
        if (isPOMProject()) //$NON-NLS-1$
        {
            getLog().warn(Messages.getString("skippompackaging"));
            return;
        }

        if ( isS2DMParProject() ){
            getLog().debug("generate manifest for par project: "+project.getName());
            ParManifestWriter writer = new ParManifestWriter();
            writer.init(getLog(), project, project.getFile().getParentFile());
            writer.write();
        }
        else{
            getLog().debug("generate manifest for bundle project: "+project.getName());
            BundleManifestWriter writer = new BundleManifestWriter();
            writer.init(getLog(), project, new File(project.getFile().getParentFile(), "generated"));
            writer.write();
        }

    }
}
